<script setup lang="ts">
import { $t } from '@/locales';
import { useNaiveForm } from '@/hooks/common/form';
import { enableStatusOptions } from '@/constants/business';
import { translateOptions } from '@/utils/common';
import type { NoticeSearchParams } from '@/service/types/system';
import type { DictDataOption } from '@/typings/global';

defineOptions({
  name: 'NoticeSearch'
});

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}
interface Props {
  sys_notice_type: DictDataOption[];
}
const props = defineProps<Props>();

const emit = defineEmits<Emits>();

const { formRef, validate, restoreValidation } = useNaiveForm();

const model = defineModel<NoticeSearchParams>('model', { required: true });

async function reset() {
  await restoreValidation();
  emit('reset');
}

async function search() {
  await validate();
  emit('search');
}
</script>

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse>
      <NCollapseItem title="筛选" name="user-search">
        <NForm ref="formRef" :model="model" label-placement="left" :label-width="100">
          <NGrid responsive="screen" item-responsive>
            <NFormItemGi span="24 s:12 m:6" label="公告标题" path="noticeTitle" class="pr-24px">
              <NInput v-model:value="model.noticeTitle" placeholder="请输入公告标题" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="公告类型" path="noticeType" class="pr-24px">
              <NSelect
                v-model:value="model.noticeType"
                placeholder="请选择公告类型"
                :options="props.sys_notice_type"
                clearable
              />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="操作人员" path="createByName" class="pr-24px">
              <NInput v-model:value="model.createByName" placeholder="请输入发布人" />
            </NFormItemGi>
            <NFormItemGi span="m:6 s:6" class="pr-24px">
              <NSpace class="w-full" justify="start">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
